<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'
import IconSelect from '@/components/ReIcon/src/Select.vue'
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        higherDeptOptions: [],
        parentId: 0,
        name: "",
        pageUrl: "",
        code: "",
        apiUrl: "",
        icon: "",
        sort: 0,
        status: 1,
        type: 1
    })
});

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="30">
            <re-col>
                <el-form-item :label="t('adminMenu.parentMenu')">
                    <el-cascader class="w-full" v-model="newFormInline.parentId"
                        :options="newFormInline.higherDeptOptions" :props="{
                            value: 'Id',
                            label: 'Name',
                            emitPath: false,
                            checkStrictly: true
                        }">
                    </el-cascader>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.menuName')" prop="name">
                    <el-input v-model="newFormInline.name" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.menuAddress')" prop="pageUrl">
                    <el-input v-model="newFormInline.pageUrl" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.menuCode')" prop="code">
                    <el-input v-model="newFormInline.code" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.frontEndComponent')" prop="apiUrl">
                    <el-input v-model="newFormInline.apiUrl" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.displayIcon')">
                    <IconSelect v-model="newFormInline.icon" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.displaySorting')" prop="sort">
                    <el-input-number v-model="newFormInline.sort" :min="0" :max="9999" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.status')" prop="status">
                    <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0"
                        :active-text="t('adminMenu.enable')" :inactive-text="t('adminMenu.disable')"
                        :style="switchStyle" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('adminMenu.type')" prop="type">
                    <el-radio-group v-model="newFormInline.type">
                        <el-radio :label="1">{{ t('adminMenu.system') }}</el-radio>
                        <el-radio :label="2">{{ t('adminMenu.catalogue') }}</el-radio>
                        <el-radio :label="3">{{ t('adminMenu.page') }}</el-radio>
                        <el-radio :label="4">{{ t('adminMenu.function') }}</el-radio>
                    </el-radio-group>
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
